home *** CD-ROM | disk | FTP | other *** search
- /*
- Program: LIST
- Program to list ASCII text files to the crt or printer.
- Written in Turbo C v1.0, by Ron Zablocki 10 Feb 87.
- Compiled using the TINY memory model; use EXE2BIN to
- convert to LIST.BIN, rename file to LIST.COM.
- */
-
- #include <stdio.h>
-
-
- #define CLEAR "\033[2J" /* ANSI.SYS escape code f/screen clear, MS-DOS */
- #define PAUSELINE 22 /* Number of lines displayed before pausing. */
- #define LST_OUTPUT "prn" /* Define standard printer/lst output, MS-DOS */
-
-
-
- /* display_intro(): displays program introduction.
- * input: none.
- * return: void.
- */
- void display_intro()
- {
- char *msg;
-
- msg =
- " LIST v1.0, placed into the public domain by Ron Zablocki\n"
- " 10 February 1987\n\n\n"
- " Filenames can be entered via the command line: LIST filename,\n"
- " or if no file is entered, you will be prompted for one. You\n"
- " have the option of listing the ASCII file to the screen or the\n"
- " printer. If the screen is selected, the display will pause\n"
- " after each screen with the option to quit the listing. If the\n"
- " printer is selected, make sure the printer is on-line and ready.\n"
- " A form feed will be sent to printer after the file is finished\n"
- " printing.\n\n\n\n";
-
- printf("%s", msg);
- }
- /* end display_intro() */
-
-
-
- /* get_filename(): gets filename to send to list device.
- * input: int argc, char *argv[].
- * return: char *.
- */
- char *get_filename (int argc, char *argv[])
- {
- char *fname;
- int count;
-
- puts(CLEAR);
- if (argc == 2) /* Filename entered on cmd line. */
- fname = argv[1];
- else {
- display_intro();
- printf("Enter filename: ");
- gets(fname);
- }
- /* Convert filename to upper case. */
- for (count = 0; count <= (strlen(fname) - 1); count++)
- fname[count] = toupper(fname[count]);
-
- return(fname);
- }
- /* end get_filename() */
-
-
-
- /* get_op_device(): gets output device, screen or printer.
- * input: char *.
- * return: int.
- */
- int get_op_device (char *filename)
- {
- char chr;
-
- puts(CLEAR);
- printf("List %s to Screen or Printer (S/P)? ", filename);
- for (;;) {
- chr = toupper(getch());
- if (chr == 'S' || chr == 'P')
- break;
- }
- return(chr == 'S') ? 1 : 2; /* 1=Screen, 2=Printer. */
- }
- /* end get_op_device() */
-
-
-
- /*
- * main().
- */
- main (int argc, char *argv[])
- {
- int ch, line, device;
- char *filename;
- FILE *f1, *f2;
-
- puts(CLEAR);
- filename = get_filename(argc, argv);
- if ((f1 = fopen(filename, "r")) == NULL) {
- printf("\n\nError: Cannot open file %s\n\n\n", filename);
- exit(1);
- }
- device = get_op_device(filename); /* Device #: 1=Screen, 2=Printer */
- if (device == 1) {
- puts("Screen\n\n");
- line = 0;
- while ((ch = getc(f1)) != EOF) {
- if (ch == '\n')
- line++;
- putchar(ch);
- if (line == PAUSELINE) {
- line = 0; /* Reset line counter. */
- printf("\n\t\tPress any key to continue, or Q to Quit...\n");
- if(toupper(getch()) == 'Q')
- break;
- }
- }
- exit(0);
- }
- else { /* List file to printer. */
- puts("Printer");
- if ((f2 = fopen(LST_OUTPUT, "w")) == NULL) {
- printf("\n\n\Error: Printer not ready...");
- exit(1);
- }
- printf("\n\n\n\t\t\tPrinting file: %s", filename);
- while ((ch = getc(f1)) != EOF)
- fputc(ch, f2);
- fprintf(f2, "%c", 12); /* Send form feed to printer. */
- fclose(f2);
- puts(CLEAR);
- printf("\nFile: %s, finished printing.\n\n\n", filename);
- }
- fclose(f1);
- }
- /* end main */